package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.base.image;
import com.hdax.dm.beans.user.User;
import com.hdax.dm.dto.querypersoninfoDto;
import com.hdax.dm.feign.imagefeign;
import com.hdax.dm.mappers.userMapper;
import com.hdax.dm.mapstucts.querypersoninfoDtoMapper;
import com.hdax.dm.service.userService;
import com.hdax.dm.utils.request.tokenutil;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class userServiceImpl extends ServiceImpl<userMapper, User> implements userService {

    @Autowired
    private querypersoninfoDtoMapper querypersoninfoDtoMapper;

    @Autowired
    private imagefeign imagefeign;

    @Override
    public CommonResponse<querypersoninfoDto> querypersoninfo(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        User user = baseMapper.selectOne(queryWrapper);
        querypersoninfoDto dtos = querypersoninfoDtoMapper.toTarget(user);
        dtos.setSex(user.getSex()+"");
        image image = imagefeign.image(Long.parseLong(String.valueOf(id)),0L,0L);
        String imgUrl =image == null ? "":image.getImgUrl();
        dtos.setHeadUrl(imgUrl);

        return ResponseUtil.returnSuccess(dtos);
    }
}
